/* tslint:disable:no-console */

import {InterfaceUser} from '@/interface/InterfaceUser';
import {ActionContext, ActionTree, Commit, Dispatch, GetterTree, MutationTree} from 'vuex';
import * as types from '../mutation-types';


import '@/interface/InterfaceType';

export default class UserStore {

    public static initState: InterfaceUser = {
        token: '',
        wechatCode: '',
        alipay: '',
        alipayName: '',
        avatar: null,
        avatarId: 0,
        cityId: 0,
        code: '',
        districtId: 0,
        income: 0,
        isDelete: 0,
        money: '0.00',
        nickname: '',
        payPoints: '0',
        phone: '',
        pid: 0,
        provinceId: 0,
        rank: null,
        rankName: '',
        share: 0,
        snapCityId: '未填写',
        snapDistrictId: '未填写',
        snapProvinceId: '未填写',
        supplier: null,
        teamCount: 0,
        userId: 0,
        userNo: '',
        userRank: 1,
        validityTime: 0,
        wxpay: '',
    };
    public static state: InterfaceUser = UserStore.initState;


    public static mutations: MutationTree<InterfaceUser> = {
        [types.USER_UPDATE](state: InterfaceUser, user: InterfaceUser) {
            state = Object.assign(state, user);
            if (state.avatarId === 0) {
                state = Object.assign(state, {
                    avatar: {
                        extension: 'jpg',
                        fileName: 'user-no-face.jpg',
                        filePath: require('@/assets/images/user-no-face.jpg'),
                        fileSize: 6103,
                        fileStatus: {id: 0, userId: state.userId, fileId: 0, content: '', type: 1, status: 1},
                        fileType: 'image',
                        fileUrl: 'localhost',
                        groupId: 2,
                        id: 0,
                        isDelete: 0,
                        isUser: 1,
                        storage: 'localhost',
                    },
                });
            }
            state = Object.assign(state, {});
        },
        [types.USER_EXIT](state: InterfaceUser) {
            state = Object.assign(state, UserStore.initState);
        },
    };


    public static action: any = {};
}
